Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circular dependency in wpcom-xhr-wrapper #42785

Merged
merged 1 commit into from
May 29, 2020

Conversation

sgomes
Copy link
Contributor

@sgomes sgomes commented May 29, 2020

lib/wpcom-xhr-wrapper was introducing a circular dependency for lib/user/utils:

client/lib/user/utils.js -> client/lib/user/index.js ->
client/lib/user/user.js -> client/lib/user/support-user-interop.js ->
client/lib/wp/browser.js -> client/lib/wpcom-xhr-wrapper/index.js ->
client/lib/user/utils.js

Since lib/wpcom-xhr-wrapper is all async anyway, we can load lib/user/utils dynamically, and avoid the circular dependency.

@cbauerman: Please ensure that Jetpack Cloud continues to work correctly with these changes.

Changes proposed in this Pull Request

  • Load lib/user/utils dynamically in lib/wpcom-xhr-wrapper, instead of using a synchronous require (which we shouldn't be using in client code anyway).

Testing instructions

Ensure any code making use of lib/wpcom-xhr-wrapper, such as Jetpack Cloud, continues to work correctly. I believe everything is working, but I've only been able to perform very minimal testing.

`lib/wpcom-xhr-wrapper` was introducing a circular dependency through
`lib/user/utils`:

```
client/lib/user/utils.js -> client/lib/user/index.js ->
client/lib/user/user.js -> client/lib/user/support-user-interop.js ->
client/lib/wp/browser.js -> client/lib/wpcom-xhr-wrapper/index.js ->
client/lib/user/utils.js
```

Since `lib/wpcom-xhr-wrapper` is all async anyway, we can load
`lib/user/utils` dynamically, and avoid the circular dependency.
@sgomes sgomes added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Type] Janitorial Jetpack Cloud Anything related to the Jetpack Cloud (cloud.jetpack.com) labels May 29, 2020
@sgomes sgomes requested review from cbauerman and a team May 29, 2020 09:44
@matticbot
Copy link
Contributor

@matticbot
Copy link
Contributor

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Webpack Runtime (~88 bytes added 📈 [gzipped])

name      parsed_size           gzip_size
manifest       +222 B  (+0.1%)      +88 B  (+0.3%)

Webpack runtime for loading modules. It is included in the HTML page as an inline script. Is downloaded and parsed every time the app is loaded.

App Entrypoints (~9066 bytes removed 📉 [gzipped])

name                   parsed_size           gzip_size
entry-domains-landing     -30720 B  (-5.5%)    -8864 B  (-5.7%)
entry-gutenboarding         -669 B  (-0.0%)     -146 B  (-0.0%)
entry-login                 -575 B  (-0.1%)     -241 B  (-0.1%)
entry-main                   +71 B  (+0.0%)     +185 B  (+0.1%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~9667 bytes added 📈 [gzipped])

name            parsed_size         gzip_size
lib-user-utils     +30963 B  (new)    +9667 B  (new)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

Copy link
Contributor

@cbauerman cbauerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm Jetpack cloud still works great! LGTM

@sgomes
Copy link
Contributor Author

sgomes commented May 29, 2020

Thank you, @cbauerman! 🙇

@sgomes sgomes merged commit d46489e into master May 29, 2020
@sgomes sgomes deleted the fix/wpcom-xhr-wrapper-circular-dependency branch May 29, 2020 15:37
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Jetpack Cloud Anything related to the Jetpack Cloud (cloud.jetpack.com) [Type] Janitorial
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants